package com.cxm.weilai;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

import java.util.Date;

/**
 * @program: weilai-cloud
 * @description: 用户信息应用
 * @author: ChenMan
 * @create: 2019-03-26 13:28
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class UserInfoApplicationService {

  public static void main(String[] args) {
//    createToken();
//    analysis();
    SpringApplication.run(UserInfoApplicationService.class, args);



  }

  private static void analysis() {
    Claims claims = Jwts.parser()
            .setSigningKey("tmax")
            .parseClaimsJws("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuaWNleW9vIiwiYXV0aG9yaXRpZXMiOiJhZG1pbiIsImV4cCI6MTY0NjAyNzQ4M30.JZsbP3ORh3J99mO4-a6U8Evws8wjGO_GUrCoAkehM9s")
            .getBody();

    System.out.println(claims);
    String username = claims.getSubject();
    System.out.println("username:"+username);
    String authority = claims.get("authorities").toString();
    System.out.println("权限："+authority);
  }

  private static void createToken() {
    String token = Jwts.builder()
                .setHeaderParam("typ","JWT")
                .setSubject("niceyoo")
                .claim("authorities","admin")
            .setExpiration(new Date(System.currentTimeMillis() + 30000))
            .signWith(SignatureAlgorithm.HS256, "tmax")
            .compact();
    System.out.println(token);
  }
}
